home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / f_tsoften.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-20  |  2.6 KB  |  108 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Copyright (C) 1998-2001 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #include <stdio.h>
  19.  
  20. #include <windows.h>
  21. #include <commctrl.h>
  22.  
  23. #include "resource.h"
  24. #include "filter.h"
  25.  
  26. extern HINSTANCE g_hInst;
  27.  
  28. ///////////////////////////////////
  29.  
  30. typedef struct MyFilterData {
  31.     bool is_first_frame;
  32. } MyFilterData;
  33.  
  34. ///////////////////////////////////
  35.  
  36. static int tsoften_run(const FilterActivation *fa, const FilterFunctions *ff) {    
  37.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  38.     Pixel *src = (Pixel *)fa->last->data;
  39.     Pixel *dst = (Pixel *)fa->dst.data;
  40.     long w, h;
  41.  
  42.     if (mfd->is_first_frame) {
  43.         mfd->is_first_frame = FALSE;
  44.  
  45.         return 0;
  46.     }
  47.  
  48.     h = fa->dst.h;
  49.     do {
  50.         w = fa->dst.w;
  51.  
  52.         do {
  53.             *dst = (((*dst&0xfefefe) + (*src&0xfefefe))>>1) + ((*src&0x010101) & (*dst&0x010101));
  54.             ++dst;
  55.             ++src;
  56.         } while(--w);
  57.  
  58.         src = (Pixel *)((char *)src + fa->last->modulo);
  59.         dst = (Pixel *)((char *)dst + fa->dst.modulo);
  60.     } while(--h);
  61.  
  62.     return 0;
  63. }
  64.  
  65. static long tsoften_param(FilterActivation *fa, const FilterFunctions *ff) {
  66.     fa->dst.offset    = fa->src.offset;
  67.     fa->dst.modulo    = fa->src.modulo;
  68.     fa->dst.pitch    = fa->src.pitch;
  69.     return FILTERPARAM_NEEDS_LAST;
  70. }
  71.  
  72. static int tsoften_start(FilterActivation *fa, const FilterFunctions *ff) {
  73.     if (!fa->filter_data)
  74.         if (!(fa->filter_data = (void *)new MyFilterData)) return 1;
  75.  
  76.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  77.  
  78.     mfd->is_first_frame = TRUE;
  79.  
  80.     return 0;
  81. }
  82.  
  83. static int tsoften_stop(FilterActivation *fa, const FilterFunctions *ff) {
  84.     MyFilterData *mfd = (MyFilterData *)fa->filter_data;
  85.  
  86.     delete mfd;
  87.     fa->filter_data = NULL;
  88.  
  89.     return 0;
  90. }
  91.  
  92.  
  93.  
  94.  
  95. FilterDefinition filterDef_tsoften={
  96.     0,0,NULL,
  97.     "motion blur",
  98.     "Blurs adjacent frames together.\n\n",
  99.     NULL,NULL,
  100.     sizeof(MyFilterData),
  101.     NULL,NULL,
  102.     tsoften_run,
  103.     tsoften_param,
  104.     NULL,
  105.     NULL,
  106.     tsoften_start,
  107.     tsoften_stop,
  108. };